<!--表格检验-->
<?php
$name='';
$nameErr='';
if($_SERVER['REQUEST_METHOD'] =='POST'){


    if(empty($_POST['fname'])){
        $nameErr = '无名走开';
    }else{
        $name = test_input($_POST['fname']);
        if (!preg_match("/^[a-zA-Z ]*$/",$name))
        {
            $nameErr = "只能输入字母哈小弟弟";
        }else{
            $nameErr = 'OJBK';
        }
    }

}

function test_input($data){
    $data = trim($data);
    $data = stripcslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
?>

<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF'])  ?>">
    姓名: <input type="text" name="fname" value="<?php echo $name;?>" >

    <span ><?php echo $nameErr; ?></span>
    <br> <input type="submit" value="提交">
</form>

<h1>收到输入</h1>
<?php
echo '姓名:'.$name;
?>

